import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../components/Login.vue'
import Home from '../components/Home.vue'
import Item from '../components/user/Item.vue'
import Reward from '../components/user/Reward.vue'
import signIn from '../components/SignIn.vue'
Vue.use(VueRouter)

const routes = [
  {path:'/' ,redirect:'login'},
  {path: '/login' ,component:Login},
  {path: '/signIn' ,component:signIn},
  {path: '/home' ,component: Home,children:[
    {path: '/item', component: Item},
    {path: '/reward', component: Reward},

  ]},

]

// Vue.use(VueRouter)

//   const routes = [
//   {
//     path: '/',
//     name: 'Home',
//     component: Home
//   }
// ]
const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  console.log("Hello");
  if(to.path !== "/login" && to.path !== "/signIn" && !sessionStorage.getItem("token"))
  {
    next("/login");
    return;
  }
  next();
})

export default router
